<template>
  <div>
    <!--面包屑导航区-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="/">商品管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>参数列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--卡片视图区域-->
    <el-card>
      <el-alert title="注意:只允许为第三级分类设置相关参数!" type='warning' :closable="false" show-icon></el-alert>
      <el-row class='cat_opt'>
        <el-col>
          <span>选择商品分类: </span>
          <el-cascader
            v-model="selectdCateKeys"
            expand-trigger='hover'
            :options="cateList"
            :props="cateProps"
            @change="handleChange"></el-cascader>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Params',
  data () {
    return {
      cateList: [],
      selectdCateKeys: [],
      cateProps: {
        value: 'cat_id',
        label: 'cat_name',
        children: 'children'
      }
    }
  },
  created() {
    this.getCateList()
  },
  methods: {
    async getCateList () {
      const { data: res } = await this.$http.get('categories')
      if (res.meta.status !== 200) {
        return this.$message.error('获取商品分类失败')
      }
      this.cateList = res.data
      console.log(this.cateList)
    },
    handleChange () {
      if (this.selectdCateKeys.length !== 3) {
        this.selectdCateKeys = []
      }
      console.log(this.selectdCateKeys = [])
    }
  }
}
</script>

<style scoped lang='less'>
.cat_opt{
  margin: 15px 0;
}
</style>
